﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;
using DLMemberPointMS.Business;
using DLMemberPointMS.Entity.ViewModel;
using DLMemberPointMS.Entity.POCOModel;
using DLMemberPointMS.Common;
using DLMemberPointMS.Web.Configs;
using System.Data.Entity.Infrastructure;
using DLMemberPointMS.Entity.DTOModel;

namespace DLMemberPointMS.Web.Controllers
{
    //[Authorize]
    //[WebApiExceptionFilterAtrribute]
    public class HomeController : Controller
    {
        readonly UsersService _usersService = new UsersService();

        public void err()
        {
            var a = 1;
            var b = 0;
            var c = a / b;
        }
        // GET: Home
        //主页
        [Authorize]
        public ActionResult Index()
        {
            return View();
        }
        //登陆
        [CustomerAllowAnonymous]
        public ActionResult SignIN()
        {

            return View();
        }
        /// <summary>
        ///登陆
        /// </summary>
        /// <param name="mod"></param>
        /// <returns></returns>
        [HttpPost]
        public ActionResult SignINRse(UsersViewModel mod)
        {

            var res = _usersService.Signin(mod);
            //Session["UserInfo"] = res.data;
            UsersDtoMdel dto = (UsersDtoMdel)res.data;
            if (res.code == code.Success)
            {
                LogHelper.Info("用户:" + dto.U_LoginName + "登陆成功");
                var returnUrl = Request["ReturnUrl"];
                var result = new OperateResult(code.Success, "验证成功，跳转至/Home/Index", "/Home/Index");
                if (!string.IsNullOrWhiteSpace(returnUrl))
                {
                    result = new OperateResult(code.Success, "验证成功，跳转至" + returnUrl, returnUrl);
                    return Json(result);
                }
                return Json(result);
            }
            else
            {
                return Json(res);
            }

        }
        /// <summary>
        /// 退出登录
        /// </summary>
        /// <returns></returns>
        public ActionResult OutLogin()
        {
            var res = _usersService.Logout();
            return Json(res, JsonRequestBehavior.AllowGet);
        }
        [CustomerAllowAnonymous]
        //404
        public ActionResult Error404()
        {
            return View();
        }

    }
}